public class Test {

    public static void main(String[] args) {
        String str3="ababcabcd";
        int index3=str3.lastIndexOf('a',4);
        System.out.println(index3);
    }
    public static void main4(String[] args) {
        String str1="abcde";
        String str2="edf";

        char ch=str1.charAt(2);
        System.out.println(ch);

        int index =str1.indexOf('a',2);//从2位置开始找a
        System.out.println(index);
        System.out.println(str1.compareTo(str2));
        System.out.println(str1.compareToIgnoreCase(str2));
    }

    public static void main3(String[] args) {
        String str1="abcdef";
        String str2="abcdef";
        System.out.println(str1==str2);
        System.out.println(str2.equals(str1));

        String str3=new String("abcd");
        String str4=new String("AbCd");
        System.out.println(str3==str4);
        System.out.println(str3.equals(str4));
        System.out.println(str3.equalsIgnoreCase(str4));
    }

    public static void main2(String[] args) {
        String str1="abcdef";
        System.out.println(str1.length());//6

        String str2=null;
        System.out.println(str2);//null
        System.out.println(str1.length());//空指针异常

        String str3="";
        System.out.println(str3.length());//0
        System.out.println(str3.isEmpty());//用于判断字符串是否为空 返回true或false
    }
    public static void main1(String[] args) {
        //直接赋值的方法， 定义字符串
        String str1="abcdef";//简写形式
        String str2=new String("hello Word!");

        //用字符数组 构造字符串
        char[]array={'a','b','c'};
        String str3=new String(array);

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
